# 21ms 3008KB 32Min +8Min
# i=int(input())
input()

bnum={int(i):True for i in input().split()}

for i in bnum: ## bnum.keys()
    if not bnum[i]:
        continue
    while i>1: 
        if i%2==0:
            i=i//2
        else:
            i=(3*i+1)//2
        if i in bnum:
            bnum[i]=False


res=[k for k,v in bnum.items() if v]

res.sort(reverse=True)
print(*res)